// 动态组件容器
import {Component, Prop, Vue} from 'vue-property-decorator'
import {deepCopy} from '@/utils/tools'


@Component({})
export default class dynamicContainer extends Vue{
    name:string = 'dynamic-container'

     // 分配动态组件 所需数据 (从store中获取相关数据)
     buildProps(propsConf){
        let cache = {};
        let _vue = this;

        Object.keys(propsConf).forEach(key =>{

            let conf = propsConf[key];
            cache[key] = _vue.getComponentData(conf.storeMethod, conf.storePath)

        })
        
        return cache
    }

    // 混合组建中 布局样式和其他样式配置
    mixStyle (...style:any[]):any{
        let cache = {};
        
        style.forEach(item  =>{
            cache = Object.assign(cache, item);
        })

        return deepCopy(cache);
    }

    // 执行数据请求方法
    getComponentData(storeMethod:formInf.storeMethod, storePath:string):any{

        let method = storeMethod || 'state'
        let data = {};
        
        if(storePath){

            data = this.$store[<string>storeMethod];

            if(storeMethod === 'state'){

                storePath.split('/').forEach(key =>{
                    data = data[key]
                })
                 
            }else{
                data = data[storePath]
            }
           
        }

        return data;
    }
    
}